package restful_apis.document_processing;

/**
 * Created by julianzliu on 5/5/2017.
 */

import com.fasterxml.jackson.databind.JsonNode;
import common.helper.json.JavaToJsonString;
import org.springframework.stereotype.Component;
import restful_apis.common.MediaTypes;
import result_reranking.entity_rank.DocumentRanking;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

import org.springframework.stereotype.Component;
import restful_apis.common.MediaTypes;
import result_reranking.entity_rank.DocumentRanking;
import textprocessing.datasources.enwikipedia.TransformerByInput;
import textprocessing.datasources.enwikipedia.TransformerByQuery;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

/**
 * Created by julianzliu on 5/4/2017.
 */


@Path("/document")
@Produces(MediaTypes.JSON_UTF8)
@Component
public class TransformerDocRest {


    private TransformerByQuery transformer;
    private TransformerByInput transformerByInput;

    public TransformerDocRest(){

        this.transformer = new TransformerByQuery();

        this.transformerByInput = new TransformerByInput();

    }


    @GET
    @Path("/_import")
    @Produces(MediaTypes.JSON_UTF8)
    public String  searchRankedDocument(
            @QueryParam("query") String query
    ){
        this.transformer.transferByTitle( query );
        this.transformer.transferByText( query );

        return "{\"status\":\"ok\"}";
    }


    @GET
    @Path("/_identity")
    @Produces(MediaTypes.JSON_UTF8)
    public String  searchSimpleDocument(
            @QueryParam("id") String id
    ){
        this.transformer.transerById( id );

        return "{\"status\":\"ok\"}";
    }

    @GET
    @Path("/_input")
    @Produces(MediaTypes.JSON_UTF8)
    public String  processPara(
            @QueryParam("id") String id,
            @QueryParam("input") String input
    ){

        this.transformerByInput.processInput( input, id);

        return "{\"status\":\"ok\"}";
    }

    @GET
    @Path("/_process")
    @Produces(MediaTypes.JSON_UTF8)
    public String  processText(
            @QueryParam("input") String input
    ){

        JsonNode ret = this.transformerByInput.processText( input );

        return JavaToJsonString.mapJavaToJson( ret );
    }

}
